<?php
/**
 * +----------------------------------------------------------------------
 * | 管理员日志控制器
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: 407593529@qq.com
 *                 ..:::::::::::'           | DATETIME: 2020/02/03
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
namespace app\admin\controller;

// 引入框架内置类
use think\facade\Request;

// 引入表格和表单构建器
use app\common\facade\MakeBuilder;
use app\common\builder\FormBuilder;
use app\common\builder\TableBuilder;

class AdminLog extends Base
{
    // 验证器
    protected $validate = 'AdminLog';

    // 当前主表
    protected $tableName = 'admin_log';

    // 当前主模型
    protected $modelName = 'AdminLog';

    // 修改
    public function edit(string $id)
    {
        $model = '\app\common\model\\' . $this->modelName;
        $info = $model::edit($id)->toArray();
        // 获取字段信息
        $columns = MakeBuilder::getAddColumns($this->tableName, $info);
        // 获取分组后的字段信息
        $groups = MakeBuilder::getAddGroups($this->modelName, $this->tableName, $columns);
        // 隐藏<显示全部>按钮
        $hideShowAll = MakeBuilder::getHideShowAll($this->tableName);

        // 构建页面
        $btn = [
            'target' => '_blank',
            'href' => url('add'),
            'icon' => 'fa fa-plus-circle',
             'class' => 'btn-success',
              'id' => '123',//修改按钮id
              'data-url' => '添加自定义属性',//添加自定义属性
        ];
        $builder = FormBuilder::getInstance()
                    ->addNumber('num', '数量')
                    ->addNumber('num1', '数量', '', '', '-10')
                    ->addNumber('num2', '数量', '', '', '0','100')
                     ->addPassword('psw', '密码')
                    ->addSelect('color5', '选择颜色', '', ['1' => '绿色', '2' => '红色', '3' => '黄色'], '3')
                    ->addSelect2('color', '选择颜色', '', ['1' => '绿色', '2' => '红色', '3' => '黄色'], '', 'multiple="multiple"', '', '请选择颜色')
                     ->addImage('pic', '图片')
                     ->addImages('pics', '多图上传')
                     ->addFile('download', '文件')
                    ->addFiles('downloads', '多文件上传', '提示信息', '', '', 'extra_class', '', true)
                    ->addEditor('content', '内容')
                    ->addButton('test', '自定义')
                    ->addButton('test', '自定义', $btn, 'a')
                    ->addHidden('id', '13')
                    ->addColor('color6', '颜色')
                    ->setPageTips('这是页面提示信息', 'success')
                    //->setFormUrl(url('addSave')),// 提交到指定方法
                    ->assign(['name' => '王小二', 'sex' => 1]);

        //ceshi构建表但
        $builder->addText('name', '姓名', '', '', ['<i class="fa fa-user"></i>']);
        $builder->addText('price', '价格', '', '', ['<i class="fa fa-fw fa-yen"></i>', '.00']);
        $builder->addText('title', '标题');
        $color = ['green' => '绿色', 'red' => '红色', 'yellow' => '黄色'];
        $builder->addRadio('color', '颜色', '', $color, 'red');
        $builder->addRadio('color2',  '颜色', '', $color, 'red', 'disabled');
        $builder->addRadio('color3', '颜色', '', $color, 'red', '', 'active');
        $builder->addCheckbox('colors',  '颜色', 'tishixinxi', $color, 'red');
        $builder->addDate('create_time', '发布时间', '', '');
        $builder->addTime('create_time', '时间', '', '15:30:27');
        $builder->addDatetime('create_time2', '发布时间');
        $builder->addDaterange('date', '日期范围');
        $builder->addTag('tags', '标签');
        $builder->addGroup(
                [
                    '基础设置' => [
                        ['text', 'title', '网站名称', '', '网站名称'],
                        ['image', 'pic', '网站LOGO', '', '/uploads/20181226/a3a4245ec095da4903c6c81123fd480d.png']
                    ],
                    '上传设置' => [
                        ['text', 'upload_file_ext', '文件格式', '', 'rar,zip,avi,rmvb,3gp,flv,mp3,mp4,txt,doc,xls,ppt,pdf,xls,docx,xlsx,doc'],
                    ]
                ]
            );
         //ceshi构建表但结束

        if ($hideShowAll) {
            $builder->hideShowAll();
        }
        $builder->hideBtn(['submit','back']);
        $groups ? $builder->addGroup($groups) : $builder->addFormItems($columns);
        return $builder->fetch();
    }

}
